/*
    在这里负责监听窗口尺寸变化时的时间监听和触发相关操作
*/

//响应式业务
import {onMounted,onUnmounted} from 'vue'

//抛出useResize
export function useResize(
    handlerFn,
    immediate = true
){

    const handler = ()=>{
        handlerFn()
    }

    //组件挂载后
    onMounted(()=>{
        window.addEventListener('resize',handler)
        //如果immediate 为true则执行
        immediate&&handler()
    })

    //卸载组件  防止内存泄漏
    onUnmounted(()=>{
        window.removeEventListener('resize',handler)
    })
}